package com.yyfax.ph.personal.subaccount;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.util.List;

public class SubAccountModel extends Model {
	private static final String TAG = SubAccountModel.class.getSimpleName();

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		SubAccountResult result = cast(obj);
		EventAgent.post(result);
	}

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getSubAccountList(token, (SubAccount) params);
	}

	private interface Service {
		@POST("account/bind/getSubAccountList")
		Observable<SubAccountResult> getSubAccountList(@Header("token") String token, @Body SubAccount params);
	}

	static class SubAccount {
		int pageNo;
		int pageSize;

		public SubAccount(int pageNo, int pageSize) {
			this.pageNo = pageNo;
			this.pageSize = pageSize;
		}
	}

	public static class SubAccountResult extends BaseResultEntity<SubAccountContent> {

	}

	public static class SubAccountBean {
		/**
		 * 用户ID
		 */
		public String userId;
		/**
		 * 进件量
		 */
		public int applyCount;
		/**
		 * 绑定时间
		 */
		public String bindTime;
		/**
		 * 手机号
		 */
		public String phone;
		/**
		 * 进件量
		 */
		public int loanCount;
		/**
		 * 姓名（若不返回，则未实名）
		 */
		public String name;
	}

	static class SubAccountContent {
		public int subCount;
		public int subApplyCount;
		public List<SubAccountBean> subList;
	}

}
